import React, { Component , Fragment} from 'react';
import {View, Text, StatusBar, Platform} from 'react-native';
import NavUtils from '$/utils/NavUtils';
import {connect} from 'react-redux';
import {initStorage} from '$/utils/storage'
import {getItem, removeItem} from '$/utils/storage'
import backPress from '$/utils/backPress'
import RNExitApp from 'react-native-exit-app';

@connect(({app}) => ({theme: app.loginTheme}))
class Welcome extends Component {

    componentDidMount() {
        NavUtils.navigation = this.props.navigation;
        NavUtils.routers = [];
        initStorage();
        // removeItem('userInfo')
        this.timer = setTimeout(this.timeout,1500);

        backPress.createBackPress(() => RNExitApp.exitApp())
    }
    componentWillUnmount() {
        if(this.timer)clearTimeout(this.timer);
    }

    timeout =  () => {
        getItem('userInfo').then(info => {
            NavUtils.go('TabBar')
        }).catch(() => {
            NavUtils.go('Login')
        })
    }

    render() {
        return (
            <Fragment>
                <StatusBar hidden={false} translucent={true} backgroundColor={'transparent'}/>
                <View style={{
                    backgroundColor: this.props.theme.background,
                    height: '100%',
                    justifyContent:'space-between',
                }}>
                    <Text style={{
                        marginTop: '35%',
                        color: '#fff',
                        fontSize: 40,
                        textAlign: 'center',
                    }}>音樂的力量</Text>
                    <Text style={{
                        textAlign: 'center',
                        color:'#fff',
                        fontSize: 20,
                        marginBottom: '15%'
                    }}>麦兜音乐</Text>
                </View>
            </Fragment>

        );
    }
}

export default Welcome;

//  npm install cnpm -g --registry=https://registry.npm.taobao.org
